package com.xm.servlet.reception_desk.coupon;

import com.alibaba.fastjson.JSON;
import com.google.gson.Gson;
import com.xm.entity.Coupons;
import com.xm.service.reception_desk.CouponsService;
import lombok.SneakyThrows;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

/**
 * @author 田顺琪
 * @date 2024-01-11
 */
@WebServlet(name = "CouponsServlet", value = "/coupons")
public class CouponsServlet extends HttpServlet {
    private final CouponsService couponsService=new CouponsService();
    @SneakyThrows
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int id=Integer.parseInt(req.getParameter("informationId"));
        int state=Integer.parseInt(req.getParameter("state"));
        List<Coupons> coupons=couponsService.getAvailableCouponsByInformationId(id,state);
        int count = couponsService.couponsCount(id,state);
        resp.getWriter().println(new Gson().toJson(coupons));
        resp.getWriter().print(new Gson().toJson(count));
    }
}
